﻿<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width,height=device-height, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0,shrink-to-fit=no" />
<meta name="format-detection" content="telephone=no" />
<!--em标准js代码，请放在页面的最上方，前面最好不要再有JS代码或JS文件-->
<script type="text/javascript" src="/js/rem.js"></script>
<link type="text/css" rel="stylesheet" href="/css/css.css" />
<link type="text/css" rel="stylesheet" href="/css/style.css" />
<title>东易日盛装饰开业盛典</title>
</head>

<body>		
	
	<div class="header">
		<a href="javascript:history.go(-1)" class="backa"></a>
	</div>	

	<div class="main main2">
		<div class="wp1">
			<div class="wp2">

				<div class="t1">上门量房</div>
				
				<div class="p7_in">
					<div class="ti">姓名</div>
					<input id="userName" name="userName" type="text" class="text">
				</div>

				<div class="p7_in">
					<div class="ti">手机号码</div>
					<input id="mobile" name="mobile" type="text" class="text">
				</div>

				<div class="p7_in">
					<div class="ti">所在小区</div>
					<input id="community" name="community" type="text" class="text">
				</div>

				<div class="p7_in">
					<div class="ti">房屋面积(㎡)</div>
					<input id="houseArea" name="houseArea" type="text" class="text">
				</div>

				<div class="p7_in">
					<div class="ti">设计师工号</div>
					<input id="desId" name="desId" type="text" class="text" value="dy">
				</div>

				<div class="p7_in">
					<div class="ti">推荐人工号</div>
					<input id="reference" name="reference" type="text" class="text" value="dy">
				</div>

				<div class="p7_in">
					<div class="ti">备注</div>
					<input id="remark" name="remark" type="text" class="textremark">
				</div>
				<span id="msg" class="p3_inp" style="color: red;text-align: center;border: none;"></span>


				<a href="javascript:;" class="go" id="bmBtn" onclick="submit();">确认</a>

			</div>
		</div>
	</div>

	<img src="/images/bodysd.jpg" alt="" class="sd">
</body>
<script type="text/javascript" src="/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="/js/base.js"></script>
<script type="text/javascript" src="/js/popups.js"></script>
<script type="text/javascript">

	$(function () {
		getDesId();
	});

	/*function getDesId() {
		$.ajax({
			url: "/designer/getDesId",
			method: "get",
			data: "",
			success: function (data) {
				$("#reference").val(data.desId)
			}
		})
	}*/

	$("#mobile").blur(function () {
		$("#msg").text("")
		var mobile = $("#mobile").val();
		if(mobile!=""){
			$.ajax({
				url: "/customer/getCustomerByMobile",
				method: "post",
				data: {mobile:mobile},
				success: function (data) {
					if (data.msg == 0){
						$("#msg").text("该手机号码为新客户")
						$("#userName").val("");
						$("#community").val("");
						$("#houseArea").val("");
						/*$("#reference").val("");
						$("#reference").attr("disabled",false);*/
					}
					if (data.msg == 1){
						var con = data.customer;
						$("#userName").val(con.name);
						$("#community").val(con.community);
						$("#houseArea").val(con.houseType);
						$("#reference").val(con.desId);
						$("#reference").attr("disabled",true);
					}
				}
			})
		}
	})

	function submit() {
		var flag=true;
		var userName=$("#userName").val();
		var mobile=$("#mobile").val();
		var community=$("#community").val();
		var houseArea=$("#houseArea").val();
		var desId=$("#desId").val();
		var reference=$("#reference").val();
		var remark=$("#remark").val();

		//非空验证
		if (!checkReference(reference)){flag=false;}
		if (!checkHouseArea(houseArea)){flag=false;}
		if (!checkCommunity(community)){flag=false;}
		if (!checkMobile(mobile)){flag=false;}
		if (!checkUserName(userName)){flag=false;}

		if(flag){
			$.ajax({
				url:"/measure/measureAdd",
				method:"post",
				data:{
					userName:userName,
					mobile:mobile,
					community:community,
					houseArea:houseArea,
					desId:desId,
					reference:reference,
					remark:remark,
				},
				success:function (data) {
					if(data>0){
						jqtoast("量房成功");
						setTimeout(function () {
							location.href="/measure"
						},2000)
					}
				}
			})
		} else {
			return ;
		}
	}

	//非空验证
	function checkUserName(userName) {
		if(userName==""){
			$("#msg").text("姓名不为空");
			return false;
		} else {
			return true;
		}
	}

	function checkMobile(mobile) {
		var mobileReg=/^1\d{10}$/;
		if(mobile==""){
			$("#msg").text("手机号码不为空");
			return false;
		}else if(!(mobileReg.test(mobile))){
			$("#msg").text("手机号码有误");
			return false;
		} else {
			return true;
		}
	}

	function checkCommunity(community) {
		if(community==""){
			$("#msg").text("所在小区不为空");
			return false;
		} else {
			return true;
		}
	}

	function checkHouseArea(houseArea) {
		if(houseArea==""){
			$("#msg").text("房屋面积不为空");
			return false;
		} else {
			return true;
		}
	}

	function checkReference(reference) {
		if(reference==""){
			$("#msg").text("推荐人不为空");
			return false;
		} else {
			return true;
		}
	}

</script>
</html>